// 销售订单相关类型定义

// 返回码枚举
export enum ResultCode {
    Success = 200,
    Fail = 500
}

// 销售订单状态枚举
export enum SalesOrderStatus {
    Draft = '草稿',           // 草稿
    Submitted = '已提交',   // 已提交
    PendingApproval = '待审批', // 待审批
    InApproval = '审批中', // 审批中
    Approved = '已审批',     // 已审批
    Rejected = '驳回',     // 驳回
    Completed = '已完成',   // 已完成
    Cancelled = '已取消'    // 已取消
}

// 结算方式枚举
export enum SettlementMethod {
    Cash = '现金',             // 现金
    BankTransfer = '银行转账', // 银行转账
    Check = '支票',           // 支票
    Credit = '信用',         // 信用
    Other = '其他'            // 其他
}

// 税率枚举
export enum TaxRate {
    Zero = 0,      // 0%
    Three = 3,     // 3%
    Six = 6,       // 6%
    Nine = 9,      // 9%
    Thirteen = 13  // 13%
}

// 销售订单基础信息
export interface SalesOrder {
    id: number
    orderSubject: string
    salesOrderNumber: string
    isSystemNumber: boolean
    customerId: number
    customerName?: string
    contactPhone?: string
    salesDepartmentId?: number
    salesDepartmentName?: string
    relatedProjectId?: number
    relatedProjectName?: string
    deliveryAddress?: string
    remarks?: string
    orderDate: string
    contactPerson?: string
    salespersonId?: number
    salespersonName?: string
    contactMethod?: string
    settlementMethod?: string
    orderStatus: string
    approvalProcessId?: number
    currentApprovalNode?: string
    createdBy: number
    createdByName?: string
    createdAt: string
    lastModifiedBy?: number
    lastModifiedByName?: string
    lastModifiedAt?: string
    details?: SalesOrderDetailItem[]
    totalAmountIncludingTax?: number
    totalAmountExcludingTax?: number
}

// 销售订单明细
export interface SalesOrderDetailItem {
    id: number
    salesOrderId: number
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    brand?: string
    salesQuantity: number
    mainUnitQuantity: number
    taxRate: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    amountIncludingTax: number
    amountExcludingTax: number
    discountRate: number
    discountAmount: number
    remarks?: string
}

// 销售订单DTO（用于列表显示）
export interface SalesOrderDto extends SalesOrder {
    // 继承自SalesOrder，包含所有主表信息和明细列表
}

// 销售订单查询输出模型（匹配后端SalesOrderQueryOutput）
export interface SalesOrderQueryOutput {
    id: number
    rowNumber: number
    salesOrderNumber: string
    orderSubject: string
    customerName: string
    salesDate: string
    orderStatus: string
    itemSummary: string
    totalAmount: number
    totalQuantity: number
    createTime: string
    createName: string
}

// 销售订单详情输出模型（匹配后端SalesOrderDetailOutput）
export interface SalesOrderDetailOutput {
    id: number
    orderSubject: string
    salesOrderNumber: string
    isSystemNumber: boolean
    salesDate: string
    customerName: string
    contactPerson?: string
    customerManagerId?: number
    contactMethod?: string
    contactPhone?: string
    departmentId?: number
    associatedProjectId?: number
    customerOrderNumber?: string
    deliveryAddress?: string
    settlementMethod?: string
    remarks?: string
    orderStatus: string
    totalAmount: number
    totalQuantity: number
    createName: string
    createTime: string
    modifierName?: string
    modifyTime?: string
    orderDetails: SalesOrderDetailItemOutput[]
}

// 销售订单明细项输出模型（匹配后端SalesOrderDetailItemOutput）
export interface SalesOrderDetailItemOutput {
    id: number
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    salesQuantity: number
    mainUnitQuantity: number
    taxRate: number
    unitPriceIncludingTax: number
    amountIncludingTax: number
    unitPriceExcludingTax: number
    amountExcludingTax: number
    discountRate: number
    discountAmount: number
    remarks?: string
}

// 分页查询结果（匹配后端APIPageing<T>，继承自APIResult<T>）
export interface APIPageing<T> {
    code: ResultCode
    message: string
    totalCount: number
    pageCount: number
    pageData: T[]
    pageIndex?: number
    pageSize?: number
}

// 获取销售订单列表查询参数（匹配后端SalesOrderQueryInput）
export interface GetSalesOrderListQuery {
    pageIndex: number
    pageSize: number
}

// 销售订单列表响应（使用后端返回的分页结构）
export interface SalesOrderListResponse {
    code: ResultCode
    message: string
    data: APIPageing<SalesOrderQueryOutput>
}

// 销售订单详情响应
export interface SalesOrderDetailResponse extends SalesOrderDetailOutput {
    // 继承自SalesOrderDetailOutput，包含所有主表信息和明细列表
}

// 操作结果响应
export interface OperationResultResponse {
    code: ResultCode
    message: string
    data?: any
}

// 创建销售订单响应
export interface CreateSalesOrderResponse {
    code: ResultCode
    message: string
    data: number // 返回新创建的订单ID
}

// 创建销售订单命令（匹配后端AddSalesOrderInput）
export interface CreateSalesOrderCommand {
    orderSubject: string
    isSystemNumber?: boolean
    salesDate: string
    customerName: string
    contactPerson?: string
    customerManagerId?: number
    contactMethod?: string
    contactPhone?: string
    departmentId?: number
    associatedProjectId?: number
    customerOrderNumber?: string
    deliveryAddress?: string
    settlementMethod?: string
    remarks?: string
    orderStatus: string
    orderDetails: CreateSalesOrderDetailCommand[]
}

// 创建销售订单明细命令
export interface CreateSalesOrderDetailCommand {
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    salesQuantity: number
    mainUnitQuantity: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    taxRate: number
    discountRate: number
    remarks?: string
}

// 更新销售订单命令
export interface UpdateSalesOrderCommand {
    id: number
    orderSubject: string
    isSystemNumber?: boolean
    salesDate: string
    customerName: string
    contactPerson?: string
    customerManagerId?: number
    contactMethod?: string
    contactPhone?: string
    departmentId?: number
    associatedProjectId?: number
    customerOrderNumber?: string
    deliveryAddress?: string
    settlementMethod?: string
    remarks?: string
    orderStatus: string
    orderDetails: UpdateSalesOrderDetailCommand[]
}

// 更新销售订单明细命令
export interface UpdateSalesOrderDetailCommand {
    id?: number
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    salesQuantity: number
    mainUnitQuantity: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    taxRate: number
    discountRate: number
    remarks?: string
}

// 删除销售订单命令
export interface DeleteSalesOrderCommand {
    id: number
}

// 获取销售订单详情查询
export interface GetSalesOrderByIdQuery {
    id: number
}

// 分页数据（简化版本，用于兼容）
export interface SimplePaged<T> {
    items: T[]
    totalCount: number
    pageCount: number
    pageIndex: number
    pageSize: number
}

// API结果（匹配后端APIResult<T>）
export interface APIResult<T> {
    code: ResultCode
    message: string
    data: T
} 